package com.lujieni.threadpool.config;

import com.lujieni.threadpool.properties.SnowflakeProperties;
import com.lujieni.threadpool.service.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @Title SnowflakeGeneratorAutoConfiguration 
* @Package com.itiaoling.equality.id.config 
* @Description 雪花id生成器自动装配
* @author 陈宇霖  
* @date 1/7/19 10:56 AM
* @version V1.0   
*/
@Configuration
@EnableConfigurationProperties(SnowflakeProperties.class)
public class SnowflakeGeneratorAutoConfiguration {

    @Autowired
    private SnowflakeProperties snowflakeProperties;

    /**
     * 创建雪花生成器
     * @return
     */
    @Bean
    public SnowflakeIdWorker snowflakeGenerator() {
        return new SnowflakeIdWorker(snowflakeProperties.getWorkId(), snowflakeProperties.getDataCenterId());
    }

}
